package com.cn.spring.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import com.cn.spring.web.logs.LogFactory;
import com.cn.spring.web.model.TUser;
import com.cn.spring.web.service.UserService;
import com.cn.spring.web.utils.YLJedisUtil;

@RestController
public class UserController {

	@Autowired
	private UserService userService;
	
	private final static Logger logger = LogFactory.getInstance().getInfo();

	@RequestMapping("/say")
	public String sayHello(HttpServletRequest reques) {
//		HttpSession  session = reques.getSession();
//		System.out.println(session.getId());
//		System.out.println(reques.getParameter("ticket"));
		System.out.println("xxxxxxxxx");
		logger.info("我是你大爷，不要喏我，要不我吃了你");
		return "aa";
	}

	@RequestMapping("/save")
	public String saveUser() {
		for (int x = 0; x < 100; x++) {
			TUser userr = new TUser();
			userService.saveUser(userr);
		}
		
		return "success" ;
	}

	@RequestMapping("/delete")
	public void deleteUser() {
		Long id = 100l;
		userService.saveUser(id);
	}
	
	@RequestMapping("/update")
	public void updateUser() {
		Long id = 32l;
		TUser user = userService.findUser(id);
		user.setName("xxxx");
		userService.updateUser(user);
	}
	
	
	@RequestMapping("/find")
	public String findUser() {
		Long id = 32l;
		TUser user = userService.findUser(id);
		System.out.println("name:"+user.getName() +" age:" +user.getAge() + " id:" + user.getId());
		return "name:"+user.getName() +" age:" +user.getAge() + " id:" + user.getId();
	}
	
	@RequestMapping("/setredis")
	public String setRedisValue(){
		System.out.println("setredis.....................");
		YLJedisUtil.setKye("111", "111",60*100);
		return "success";
	}
	
	@RequestMapping("/getredis")
	public String getRedisValue(){
		System.out.println("getredis..........................");
		String getkey = YLJedisUtil.getKey("111");
		return getkey;
	}
}
